package com.blog.config;

import com.rabbitmq.client.AMQP;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 任浩
 * @version 1.0
 *
 * 这是rabbitmq的配置类。
 */

@Configuration
public class RabbitMQConfig {

    //创建一个的队列。用于接收系统通知的消息。
    @Bean("sysytemQueue")
    public Queue queue(){
        return QueueBuilder.durable("queue").build();
    }

    //创建一个direct类型交换机
    @Bean("directExchange")
    public DirectExchange directExchange(){
        return new DirectExchange("exchange");
    }

    //声明队列绑定到交换机
    @Bean("binding")
    public Binding binding(@Qualifier("sysytemQueue") Queue queue,
                           @Qualifier("directExchange") DirectExchange directExchange){
        return BindingBuilder.bind(queue).to(directExchange).with("info");
    }

    //创建一个接收发布新帖子的，搜索消息。
    @Bean("SearchQueue")
    public Queue searchQueue(){
        return QueueBuilder.durable("searchQueue").build();
    }

    //创建一个接收新发布的帖子信息的交换机。
    @Bean("SearchDirect")
    public DirectExchange searchDirectExchange(){
        return new DirectExchange("searchExchange");
    }

    //声明交换机和队列的绑定关系。
    @Bean("searchBinding")
    public Binding searchBinding(@Qualifier("SearchQueue") Queue queue,
                                                    @Qualifier("SearchDirect") DirectExchange directExchange ){
        return BindingBuilder.bind(queue).to(directExchange).with("search");
    }

    //创建一个删除es中数据的交换机和队列
    @Bean("DeleteQueue")
    public Queue deleteQueue(){
        return QueueBuilder.durable("deleteQueue").build();
    }

    //创建一个接收新发布的帖子信息的交换机。
    @Bean("DeleteDirect")
    public DirectExchange deleteDirectExchange(){
        return new DirectExchange("deleteExchange");
    }

    //声明交换机和队列的绑定关系。
    @Bean("deleteBinding")
    public Binding deleteBinding(@Qualifier("DeleteQueue") Queue queue,
                                 @Qualifier("DeleteDirect") DirectExchange directExchange ){
        return BindingBuilder.bind(queue).to(directExchange).with("del");
    }

}